//
//  FXUserInfo.m
//  FetionDataStructure
//
//  Created by Ronnie on 08-12-2.
//  Copyright 2008 __MyCompanyName__. All rights reserved.
//

#import "FXUserInfo.h"

@implementation FXSysMessage

- (id)initWithLParam:(LPARAM)lp WParam:(WPARAM)wp
{
	self = [super init];
	lParam = lp;
	wParam = wp;
	return self;
}
- (LPARAM)getLParam
{
	return lParam;
}
- (WPARAM)getWParam
{
	return wParam;
}

@end


@implementation FXUserInfo

#pragma mark init methods

+ (id)fxUserWithAccount:(const Fetion_Account*)account
{
	return [[FXUserInfo alloc] initWithAccount:account];
}

- (id)initWithAccount:(const Fetion_Account*)account
{
	@synchronized(self)
	{
		self = [super init];		
		user_account = account;
		user_showName = [[NSString stringWithUTF8String:fx_get_account_show_name(user_account, false)] retain];
	}	
		user_isPc = fx_is_pc_user_by_account(user_account);
		user_isAuthed = fx_is_authed_by_id(user_account->id);
		user_isInBlackList = fx_is_InBlacklist_by_account(user_account);
		user_isOnline = fx_is_on_line_by_account(user_account);
		user_state = fx_get_online_status_by_account(user_account);
		userOf_groupId = fx_get_account_group_id (user_account);
		
	return self;
}

- (void) dealloc
{
	[user_showName release];
	[super dealloc];
}

- (void)updateSelfInfo
{
	@synchronized(self)
	{
		// bug here, if i update the show name, it will wrong
		//fx_updata_account_info_by_id(user_account->id);
		user_state = fx_get_online_status_by_id(user_account->id);
		user_showName = [[NSString stringWithUTF8String:fx_get_account_show_name(user_account, false)] retain];
	}
}


- (void)updateUserName
{
	[user_showName release];
	user_showName = [[NSString stringWithUTF8String:fx_get_account_show_name(user_account, false)] retain];
}

- (long)userID
{
	return user_account->id;
}
- (NSString*)userName
{
	return user_showName;
}

- (NSString*)userImpresa
{
	//bool notDone = true;
	NSString* result = nil;
	@synchronized(self)
	{
		result = [NSString stringWithUTF8String:user_account->personal?user_account->personal->impresa?user_account->personal->impresa:"":""];
	}
	return result;
}

- (int)userState
{
	return user_state;
}

- (BOOL)isInBlackList
{
	return fx_is_InBlacklist_by_id([self userID]);
}

- (int)groupId
{
	return userOf_groupId;
}
- (void)setUserGroupId:(int)gid
{
	userOf_groupId = gid;
}

//- (id)copyWithZone:(NSZone *)zone {
//	return [self retain];
//}


- (const Fetion_Account*)getFetionAccount
{
	return user_account;
}

- (void)PrintUserInfo
{
	NSLog(@"\tThe user %@==%@ id is %i. Buddly list is %d, %i. state is %i, %i. mobile is %s", 
		  user_showName,[NSString stringWithUTF8String:user_account->local_name?user_account->local_name:""],
		  user_account->id, user_account->group_id, userOf_groupId, user_state, user_isOnline, user_account->personal?user_account->personal->mobile_no:"test");
}

@end
